package com.tmz.inter;

import java.io.Serializable;
import java.util.Iterator;
import java.util.Map;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.tmz.domain.User;
import com.tmz.utils.UsuarioHabilitado;



public class InterAutenticacion implements Interceptor {

    public void destroy() { }
    public void init() { }
    public String intercept(ActionInvocation actionInvocation) throws Exception {
        Map session = actionInvocation.getInvocationContext().getSession();
        User usuario = (User) session.get("usuario");
        if (usuario == null) {
            return Action.LOGIN;
        } else {
            Action action = (Action) actionInvocation.getAction();
            if (action instanceof UsuarioHabilitado) {
                ((UsuarioHabilitado) action).setUsuario(usuario);
            }
            return actionInvocation.invoke();
        }
    }

}
